﻿#pragma once

#include "OutputBase.h"
#include "EulerSystem.h"
class EulerSystem;

class VTKOutput : public OutputBase
{
public:
  VTKOutput(const EulerSystem& sys)
    : _sys(sys)
  {
  }
  ~VTKOutput(){};

  virtual void Execute() override
  {
    const auto& sln = _sys.Solution();
    const auto& mesh = _sys.GetMesh();
    vtkm::cont::DataSet out_vtk;
    out_vtk.AddCoordinateSystem(mesh.GetCoordinate());
    out_vtk.SetCellSet(mesh.GetCellSet());
    for (UInt8 eq = 0; eq < 5; eq++)
    {
      out_vtk.AddCellField("variable" + std::to_string(eq), ArrayHandle<FloatDefault>{});
    }
    for (UInt8 eq = 0; eq < EulerSystem::NUM_VARIABLES; eq++)
    {
      Invoker{}(EulerSystem::WriteVariable{ eq }, sln, out_vtk.GetField(eq));
    }

    vtkm::io::VTKDataSetWriter writer("out.vtk");
    writer.WriteDataSet(out_vtk);
  }

private:
  const EulerSystem& _sys;
};
